home *** CD-ROM | disk | FTP | other *** search
AmigaBASIC Source Code | 1995-03-18 | 2.3 KB | 102 lines |
- ' This program will compute the amount of memory an array will
- ' require from the system. Just finish typing the array with your
- ' variable (remembering to add special characters which define the
- ' type ($, !, #, %) of the variable.
- '
- ' written by: William H. Bartell
- '
- ' This program may be freely distributed, but please
- ' include my name with all copies.
- '
-
- start:
- DIM dm&(255)
- FOR i%= 0 TO 255
- dm&(i%)=0
- NEXT i%
-
- newdim:
- n%= 0
- CLS
- PRINT "Complete the DIMension statement below to compute"
- PRINT "how much memory the array will require."
- PRINT "Enter EXIT to quit.
- LOCATE 6,5
- LINE INPUT "DIM ";d$
- IF UCASE$(LEFT$(d$,1))="E" AND INSTR(d$,"(")=0 THEN END
- LSET d$= d$
- z%= INSTR(d$," ")
- WHILE z%
- d$= LEFT$(d$,z%-1)+RIGHT$(d$,z%+1)
- z%= INSTR(d$," ")
- WEND
- IF LEN(d$)=0 THEN GOTO badinput
- p1%= INSTR(d$,"(")
- IF p1%=0 OR p1%<2 OR p1%>41 THEN GOTO badinput
- prec%= ASC(MID$(d$,p1%-1,1))
- IF prec%=37 THEN
- bytlen%= 2
- ELSEIF prec%=33 OR prec%=38 OR prec%=46 OR (prec%>47 AND prec%<58) OR (prec%>64 AND prec%<91) OR (prec%>96 AND prec%<123) THEN
- bytlen%= 4
- ELSEIF prec%=36 THEN
- bytlen%= 5
- ELSEIF prec%=35 THEN
- bytlen%= 8
- ELSE
- GOTO badinput
- END IF
- p2%= INSTR(d$,")")
- IF p2%=0 THEN GOTO badinput
- p2%= INSTR(d$,",")
- WHILE p2%
- GOSUB addit
- p2%= INSTR(p1%+1,d$,",")
- WEND
- p2%= INSTR(d$,")")
- GOSUB addit
- total&= 1
- FOR i%= 1 TO n%
- total&= total&*(dm&(i%)+1)
- NEXT i%
- total&= total&*bytlen%
- total&= total&+12+2*(n%-1)
- IF bytlen%=5 THEN
- total#= total&+0.5
- total&= CLNG(total#)
- END IF
- LOCATE 8,1
- PRINT "The total memory requirement for this"
- PRINT "variable array is ";
- IF bytlen%=5 THEN PRINT "at least ";
- PRINT total&;" bytes."
- IF bytlen%=5 THEN
- PRINT "Add 1 byte for all characters which may"
- PRINT "be used in the array during program execution."
- PRINT "This will probably mean making a guess as to"
- PRINT "how many characters there will be."
- END IF
- GOSUB hold
- GOTO newdim
-
- addit:
- n%= n%+1
- dm&(n%)= VAL(MID$(d$,p1%+1,p2%-p1%))
- p1%= p2%
- RETURN
-
- badinput:
- LOCATE 8,1
- PRINT CHR$(7);"Bad DIM statement, please try again."
- GOSUB hold
- GOTO newdim
-
- hold:
- PRINT
- PRINT "Press ANY key to continue..."
- z$= ""
- WHILE z$=""
- z$= INKEY$
- WEND
- RETURN
-
-